import { encode, decode } from 'js-base64';
const storaKey = "SRC_STORA"

export const setStora = (data,key,type) =>{
  if (Object.prototype.toString.call(type) !== '[object Boolean]' )
    type = true
  if(!key) key = storaKey
  data = encode(JSON.stringify(data))
  if(type)
    localStorage.setItem(data)
  else 
    sessionStorage.setItem(data)
}

export const getStora = (key,type) =>{
  if (Object.prototype.toString.call(type) !== '[object Boolean]' )
    type = true
  let data
  if(type)
    data = localStorage.getItem(data)
  else 
    data = sessionStorage.getItem(data)
  return JSON.parse(decode(data))
}

export const removeStora = (key,type) =>{
  if (Object.prototype.toString.call(type) !== '[object Boolean]' )
    type = true
  data = JSON.stringify(data)
  if(type)
    localStorage.removeItem(data)
  else 
    sessionStorage.removeItem(data)
}